#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/*
 * Copyright © 2014, Finium Sdn Bhd, All Rights Reserved
 * 
 * DTOUtil.java
 * Modification History
 * *************************************************************
 * Date				Author						Comment
 * Sep 7, 2012		Venkaiah Chowdary Koneru	Created
 * *************************************************************
 */
package ${package}.dto;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.util.StringUtils;

/**
 * Utility for DTO classes.
 * 
 * @author Venkaiah Chowdary Koneru
 */
public final class DTOUtil
{
    /**
     * Constructor. Private to prevent unnecessary instantiation.
     */
    private DTOUtil()
    {
    }

    /**
     * Checks whether the given property is empty (null and blank) for the
     * passed in object. Only valid for String properties
     * 
     * @param obj
     * @param property
     * @return true | false
     */
    public static boolean isEmpty(Object obj, String property)
    {
        if (obj == null || !StringUtils.hasText(property))
        {
            return true;
        }

        try
        {
            String value = (String) PropertyUtils.getProperty(obj, property);

            return !StringUtils.hasText(value);
        }
        catch (IllegalAccessException e)
        {
            return true;
        }
        catch (InvocationTargetException e)
        {
            return true;
        }
        catch (NoSuchMethodException e)
        {
            return true;
        }
    }
}
